//@author A0101119Y
#ifndef GACCOUNTSREQUESTAGENT_H
#define GACCOUNTSREQUESTAGENT_H

#include "Poco/Net/HTTPClientSession.h"
#include "Poco/Net/HTTPSClientSession.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/Util/Application.h"
#include "Poco/StreamCopier.h"
#include "Poco/Path.h"
#include "Poco/URI.h"
#include "Poco/Exception.h"
#include "GCalParser.h"
#include "GCalVariableMgr.h"
#include "GoogleRequestAgent.h"
#include "CommonObjects.h"
#include <string>
#include <vector>
#include <sstream>
#include <map>

namespace Twentyfifth {

	class GAccountsRequestAgent : public GoogleRequestAgent {
	protected:
		static const std::string GACCOUNTS_HOSTNAME;
		static const std::string GACCOUNTS_PATH_AUTH;
		static const std::string GACCOUNTS_PATH_TOKEN;
		static const std::string LABEL_CLIENT_ID;
		static const std::string LABEL_CLIENT_SECRET;
		static const std::string LABEL_SCOPE;
		static const std::string LABEL_DEVICE_CODE;
		static const std::string LABEL_USER_CODE;
		static const std::string LABEL_CODE;
		static const std::string LABEL_VERIFICATION_URL;
		static const std::string LABEL_EXPIRES_IN;
		static const std::string LABEL_INTERVAL;
		static const std::string LABEL_TOKEN_TYPE;
		static const std::string LABEL_REFRESH_TOKEN;
		static const std::string LABEL_ACCESS_TOKEN;
		static const std::string LABEL_GRANT_TYPE;
		static const std::string LABEL_SEPARATOR;
		static const std::string LABEL_AND;
		static const std::string LABEL_ERROR;
		static const std::string GACCOUNTS_SCOPE;
		static const std::string GACCOUNTS_GRANT_TYPE;
		static const std::string VALUE_JSON;
		static const std::string VALUE_FORM_URLENCODED;
		static const std::string VALUE_ACCESS_DENIED;
		static const std::string MESSAGE_NAVIGATE_TO_URL;
		static const std::string MESSAGE_EXCEPTION_REFRESH;
		static const std::string MESSAGE_EXCEPTION_ACCESS_DENIED;
		static const std::string DUMMY_STRING;
		static const int LIMIT_TIMEOUT_SECONDS;
		std::string clientId;
		std::string clientSecret;
		std::string refreshToken;
		std::string accessToken;
		std::string tokenType;
		int expiresIn;
		GCalParser parser;
		GCalVariableMgr variablemgr;
		void firstTokenRetrieval(std::string deviceCode, int interval);
	public:
		GAccountsRequestAgent();
		GAccountsRequestAgent(std::string id, std::string secret);
		void setClientId(std::string id);
		void setClientSecret(std::string secret);
		Status firstAuthenticate();
		void refreshAccessToken();
	};

}
#endif // !GACCOUNTSREQUESTAGENT_H
